gem 'ibm_db'
require 'mswin32/ibm_db'  
module SpTester

 def simpleTest sql , conn
         stmt = IBM_DB::prepare conn, sql
         return_value = []
         index=0
         sql.scan(/\?/).each{|word|
               if word=~/\?/
                   puts word
				    return_value[index]=99
                    IBM_DB::bind_param stmt, index+1,   "return_value[#{index}]" , IBM_DB::SQL_PARAM_OUTPUT 
                   puts index+1
                   index = index +1
               end
              
         }
      
         IBM_DB::execute(stmt)
		 
		  return_value.each{|e|	  puts e	   }		 
         assert_equal(0,return_value[0])
         return_value
 end
 
 
 def dataTest sql , conn
         stmt = IBM_DB::prepare conn, sql
         return_value = []
         #return_num="teste"
         index=0
         sql.scan(/\?/).each{|word|
         	    return_value[index]=99
               IBM_DB::bind_param stmt, index+1, "return_value[#{index}]" , IBM_DB::SQL_PARAM_OUTPUT
               index = index +1
         }
        
         IBM_DB::execute(stmt)
         assert_equal(0,return_value[0])
         if block_given?
             while (row = IBM_DB::fetch_array(stmt))
                 yield row
             end
         end
         return_value
 end
 
 def query sql , conn
      stmt2 = IBM_DB::exec conn, sql
      if block_given?
          while (row = IBM_DB::fetch_array stmt2)
              yield row
          end
      end
 end

 def tmTest sql, conn, ty
     t=Time.now
     simpleTest sql, conn
     Time.now - t
  
 end
 def withConn db, user, pass
   # IBM_DB::connect 'webduke', 'web_dev2', 'ebiz02vs'  
   conn=  IBM_DB::connect db, user, pass  

   yield conn

  ensure
   IBM_DB::close conn  unless conn.nil?
  end

  end
